﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Security;

namespace CodeStash.Utils
{
    public static class WebSiteUtils
    {
        public static bool IsUserLoggedIn()
        {
            return Membership.GetUser() != null;
        }

        public static string GetCodeClass(string languageCode)
        {
            return string.Format("{0}", languageCode);
        }

        public static string GetTagClass(decimal category, decimal articles)
        {
            if (articles == 0) return string.Empty;

            int result = (int)(10 * (category / articles));
            if (result <= 1)
                return "tag1";
            if (result <= 2)
                return "tag2";
            if (result <= 5)
                return "tag3";
            if (result <= 10)
                return "tag4";
            if (result <= 20)
                return "tag5";
            if (result <= 30)
                return "tag6";
            return result <= 50 ? "tag7" : "tag8";
        }

        public static bool NotNullAndHasValues(IEnumerable<object> values)
        {
            return (values.Any());
        }

    }

}